/**
* <p> title �� StatisticsUtil.java</p>
* <p> package �� cn.edu.hit.education.utils</p>
* <p> description ��TODO</p>
* <p> copyright �� ��������ҵ��ѧ(C) 2019</p>
* <p> company �� ��������ҵ��ѧAS&MT</p>
* <p> author �� ��ѩ�� jinxuesong@163.com</p>
* <p> date �� 2021��4��22�� ����11:28:52</p>
* <p> version �� v1.0 </p>
*
* Modification  History:
* Date         Author        Version        Discription
* -----------------------------------------------------------------------------------
* 2021��4��22��       ��ѩ��          1.0             1.0
* Why & What is modified: <�޸�ԭ������>
*/
package cn.edu.hit.education.utils;

import java.util.ArrayList;
import java.util.List;

import cn.edu.hit.education.model.StatisticsInfo;
import cn.edu.hit.education.pojo.Course;
import cn.edu.hit.education.pojo.ExCourse;
import cn.edu.hit.education.pojo.ExSchedule;
import cn.edu.hit.education.pojo.Schedule;

public class StatisticsUtil {
	public static void processCourseScheduleData(List<Course> courses){
		double sum_credicts = 0;
		double sum_credicts_centralize_hour = 0;
		double sum_periods_centralize_hour = 0;
		double sum_theoretical_centralize_hour = 0;
		double sum_experiment_centralize_hour = 0;
		
		double sum_credicts_centralize_week = 0;
		double sum_periods_centralize_week = 0;
		double sum_theoretical_centralize_week = 0;
		double sum_experiment_centralize_week = 0;
		
		double sum_credicts_sparse_hour = 0;
		double sum_periods_sparse_hour = 0;
		double sum_theoretical_sparse_hour = 0;
		double sum_experiment_sparse_hour = 0;
		
		double sum_credicts_sparse_week = 0;
		double sum_periods_sparse_week = 0;
		double sum_theoretical_sparse_week = 0;
		double sum_experiment_sparse_week = 0;
		
		if(courses != null && courses.size() > 0){
			for (Course course : courses) {
				sum_credicts += (course.getCredits() == null ? 0 : course.getCredits());
				
				if(course.getUnit() == null || course.getUnit().trim().equals("时")){
					if(course.getMethod().trim().equals("分散")){
						sum_credicts_sparse_hour += course.getCredits();
						sum_periods_sparse_hour += (course.getPeriod() == null ? 0 : course.getPeriod());
						sum_theoretical_sparse_hour += (course.getTheoretical() == null ? 0 : course.getTheoretical());
						sum_experiment_sparse_hour += (course.getExperiment() == null ? 0 : course.getExperiment());
					}else{
						sum_credicts_centralize_hour += course.getCredits();
						sum_periods_centralize_hour += (course.getPeriod() == null ? 0 : course.getPeriod());
						sum_theoretical_centralize_hour += (course.getTheoretical() == null ? 0 : course.getTheoretical());
						sum_experiment_centralize_hour += (course.getExperiment() == null ? 0 : course.getExperiment());
					}
				}else if(course.getUnit().trim().equals("周")){
					if(course.getMethod().trim().equals("分散")){
						sum_credicts_sparse_week += course.getCredits();
						sum_periods_sparse_week += (course.getPeriod() == null ? 0 : course.getPeriod());
						sum_theoretical_sparse_week += (course.getTheoretical() == null ? 0 : course.getTheoretical());
						sum_experiment_sparse_week += (course.getExperiment() == null ? 0 : course.getExperiment());
					}else{
						sum_credicts_centralize_week += course.getCredits();
						sum_periods_centralize_week += (course.getPeriod() == null ? 0 : course.getPeriod());
						sum_theoretical_centralize_week += (course.getTheoretical() == null ? 0 : course.getTheoretical());
						sum_experiment_centralize_week += (course.getExperiment() == null ? 0 : course.getExperiment());
					}
					
				}else{	
					
				}
			}
			
			Course sum = new Course();
			sum.setName("小  计[集中，时]");
			sum.setCredits(sum_credicts_centralize_hour);
			sum.setPeriod(sum_periods_centralize_hour);
			sum.setTheoretical(sum_theoretical_centralize_hour);
			sum.setExperiment(sum_experiment_centralize_hour);
			sum.setUnit("时");
			sum.setMethod("集中");
			courses.add(sum);
			
			sum = new Course();
			sum.setName("小  计[集中，周]");
			sum.setCredits(sum_credicts_centralize_week);
			sum.setPeriod(sum_periods_centralize_week);
			sum.setTheoretical(sum_theoretical_centralize_week);
			sum.setExperiment(sum_experiment_centralize_week);
			sum.setUnit("周");
			sum.setMethod("集中");
			courses.add(sum);
			
			sum = new Course();
			sum.setName("小  计[分散，时]");
			sum.setCredits(sum_credicts_sparse_hour);
			sum.setPeriod(sum_periods_sparse_hour);
			sum.setTheoretical(sum_theoretical_sparse_hour);
			sum.setExperiment(sum_experiment_sparse_hour);
			sum.setUnit("时");
			sum.setMethod("分散");
			courses.add(sum);
			
			sum = new Course();
			sum.setName("小  计[分散，时]");
			sum.setCredits(sum_credicts_sparse_week);
			sum.setPeriod(sum_periods_sparse_week);
			sum.setTheoretical(sum_theoretical_sparse_week);
			sum.setExperiment(sum_experiment_sparse_week);
			sum.setUnit("周");
			sum.setMethod("分散");
			courses.add(sum);
			
			sum = new Course();
			sum.setName("小  计");
			sum.setCredits(sum_credicts);
			courses.add(sum);
		}
	}
	
	public static List<StatisticsInfo> processCourseInformationData(List<ExCourse> courses){
		List<StatisticsInfo> sis = new ArrayList<StatisticsInfo>();
		
		double sum_credicts = 0;
		double sum_credicts_centralize_hour = 0;
		double sum_periods_centralize_hour = 0;
		double sum_theoretical_centralize_hour = 0;
		double sum_experiment_centralize_hour = 0;
		
		double sum_credicts_centralize_week = 0;
		double sum_periods_centralize_week = 0;
		double sum_theoretical_centralize_week = 0;
		double sum_experiment_centralize_week = 0;
		
		double sum_credicts_sparse_hour = 0;
		double sum_periods_sparse_hour = 0;
		double sum_theoretical_sparse_hour = 0;
		double sum_experiment_sparse_hour = 0;
		
		double sum_credicts_sparse_week = 0;
		double sum_periods_sparse_week = 0;
		double sum_theoretical_sparse_week = 0;
		double sum_experiment_sparse_week = 0;
		
		if(courses != null && courses.size() > 0){
			for (ExCourse course : courses) {
				List<Schedule> schedules = course.getSchedules();
				if(schedules != null && schedules.size() > 0){
					for (Schedule schedule : schedules) {
						if(schedule == null || schedule.getOpened() == 0)
							continue;
						
						sum_credicts += (course.getCredits() == null ? 0 : course.getCredits());
						
						if(course.getUnit() == null || course.getUnit().trim().equals("时")){
							if(course.getMethod().trim().equals("分散")){
								sum_credicts_sparse_hour += course.getCredits();
								sum_periods_sparse_hour += (course.getPeriod() == null ? 0 : course.getPeriod());
								sum_theoretical_sparse_hour += (course.getTheoretical() == null ? 0 : course.getTheoretical());
								sum_experiment_sparse_hour += (course.getExperiment() == null ? 0 : course.getExperiment());
							}else{
								sum_credicts_centralize_hour += course.getCredits();
								sum_periods_centralize_hour += (course.getPeriod() == null ? 0 : course.getPeriod());
								sum_theoretical_centralize_hour += (course.getTheoretical() == null ? 0 : course.getTheoretical());
								sum_experiment_centralize_hour += (course.getExperiment() == null ? 0 : course.getExperiment());
							}
						}else if(course.getUnit().trim().equals("周")){
							if(course.getMethod().trim().equals("分散")){
								sum_credicts_sparse_week += course.getCredits();
								sum_periods_sparse_week += (course.getPeriod() == null ? 0 : course.getPeriod());
								sum_theoretical_sparse_week += (course.getTheoretical() == null ? 0 : course.getTheoretical());
								sum_experiment_sparse_week += (course.getExperiment() == null ? 0 : course.getExperiment());
							}else{
								sum_credicts_centralize_week += course.getCredits();
								sum_periods_centralize_week += (course.getPeriod() == null ? 0 : course.getPeriod());
								sum_theoretical_centralize_week += (course.getTheoretical() == null ? 0 : course.getTheoretical());
								sum_experiment_centralize_week += (course.getExperiment() == null ? 0 : course.getExperiment());
							}
							
						}else{	
							
						}
						
					}
				}
			}
			
			StatisticsInfo sum = new StatisticsInfo();
			sum.setName("小  计[集中，时]");
			sum.setCredits(sum_credicts_centralize_hour);
			sum.setPeriod(sum_periods_centralize_hour);
			sum.setTheoretical(sum_theoretical_centralize_hour);
			sum.setExperiment(sum_experiment_centralize_hour);
			sum.setUnit("时");
			sum.setMethod("集中");
			sis.add(sum);
			
			sum = new StatisticsInfo();
			sum.setName("小  计[集中，周]");
			sum.setCredits(sum_credicts_centralize_week);
			sum.setPeriod(sum_periods_centralize_week);
			sum.setTheoretical(sum_theoretical_centralize_week);
			sum.setExperiment(sum_experiment_centralize_week);
			sum.setUnit("周");
			sum.setMethod("集中");
			sis.add(sum);
			
			sum = new StatisticsInfo();
			sum.setName("小  计[分散，时]");
			sum.setCredits(sum_credicts_sparse_hour);
			sum.setPeriod(sum_periods_sparse_hour);
			sum.setTheoretical(sum_theoretical_sparse_hour);
			sum.setExperiment(sum_experiment_sparse_hour);
			sum.setUnit("时");
			sum.setMethod("分散");
			sis.add(sum);
			
			sum = new StatisticsInfo();
			sum.setName("小  计[分散，时]");
			sum.setCredits(sum_credicts_sparse_week);
			sum.setPeriod(sum_periods_sparse_week);
			sum.setTheoretical(sum_theoretical_sparse_week);
			sum.setExperiment(sum_experiment_sparse_week);
			sum.setUnit("周");
			sum.setMethod("分散");
			sis.add(sum);
		}
		
		return sis;
	}
	
	public static List<StatisticsInfo> processScheduleInformationData(List<ExSchedule> exSchedules){
		List<StatisticsInfo> sis = new ArrayList<StatisticsInfo>();
		double sum_credicts = 0;
		double sum_credicts_centralize_hour = 0;
		double sum_periods_centralize_hour = 0;
		double sum_theoretical_centralize_hour = 0;
		double sum_experiment_centralize_hour = 0;
		
		double sum_credicts_centralize_week = 0;
		double sum_periods_centralize_week = 0;
		double sum_theoretical_centralize_week = 0;
		double sum_experiment_centralize_week = 0;
		
		double sum_credicts_sparse_hour = 0;
		double sum_periods_sparse_hour = 0;
		double sum_theoretical_sparse_hour = 0;
		double sum_experiment_sparse_hour = 0;
		
		double sum_credicts_sparse_week = 0;
		double sum_periods_sparse_week = 0;
		double sum_theoretical_sparse_week = 0;
		double sum_experiment_sparse_week = 0;
		
		if(exSchedules != null && exSchedules.size() > 0){
			for (ExSchedule exSchedule : exSchedules) {
				Course course = exSchedule.getCourse();
				if(exSchedule.getOpened() == 0)
					continue;
				
				sum_credicts += (course.getCredits() == null ? 0 : course.getCredits());
				
				if(course.getUnit() == null || course.getUnit().trim().equals("时")){
					if(course.getMethod().trim().equals("分散")){
						sum_credicts_sparse_hour += exSchedule.getCredits();
						sum_periods_sparse_hour += (exSchedule.getPeriod() == null ? 0 : exSchedule.getPeriod());
						sum_theoretical_sparse_hour += (exSchedule.getTheoretical() == null ? 0 : exSchedule.getTheoretical());
						sum_experiment_sparse_hour += (exSchedule.getExperiment() == null ? 0 : exSchedule.getExperiment());
					}else{
						sum_credicts_centralize_hour += exSchedule.getCredits();
						sum_periods_centralize_hour += (exSchedule.getPeriod() == null ? 0 : exSchedule.getPeriod());
						sum_theoretical_centralize_hour += (exSchedule.getTheoretical() == null ? 0 : exSchedule.getTheoretical());
						sum_experiment_centralize_hour += (exSchedule.getExperiment() == null ? 0 : exSchedule.getExperiment());
					}
				}else if(course.getUnit().trim().equals("周")){
					if(course.getMethod().trim().equals("分散")){
						sum_credicts_sparse_week += exSchedule.getCredits();
						sum_periods_sparse_week += (exSchedule.getPeriod() == null ? 0 : exSchedule.getPeriod());
						sum_theoretical_sparse_week += (exSchedule.getTheoretical() == null ? 0 : exSchedule.getTheoretical());
						sum_experiment_sparse_week += (exSchedule.getExperiment() == null ? 0 : exSchedule.getExperiment());
					}else{
						sum_credicts_centralize_week += exSchedule.getCredits();
						sum_periods_centralize_week += (exSchedule.getPeriod() == null ? 0 : exSchedule.getPeriod());
						sum_theoretical_centralize_week += (exSchedule.getTheoretical() == null ? 0 : exSchedule.getTheoretical());
						sum_experiment_centralize_week += (exSchedule.getExperiment() == null ? 0 : exSchedule.getExperiment());
					}
					
				}else{	
					
				}
			}
			
			StatisticsInfo sum = new StatisticsInfo();
			sum.setName("小  计[集中，时]");
			sum.setCredits(sum_credicts_centralize_hour);
			sum.setPeriod(sum_periods_centralize_hour);
			sum.setTheoretical(sum_theoretical_centralize_hour);
			sum.setExperiment(sum_experiment_centralize_hour);
			sum.setUnit("时");
			sum.setMethod("集中");
			sis.add(sum);
			
			sum = new StatisticsInfo();
			sum.setName("小  计[集中，周]");
			sum.setCredits(sum_credicts_centralize_week);
			sum.setPeriod(sum_periods_centralize_week);
			sum.setTheoretical(sum_theoretical_centralize_week);
			sum.setExperiment(sum_experiment_centralize_week);
			sum.setUnit("周");
			sum.setMethod("集中");
			sis.add(sum);
			
			sum = new StatisticsInfo();
			sum.setName("小  计[分散，时]");
			sum.setCredits(sum_credicts_sparse_hour);
			sum.setPeriod(sum_periods_sparse_hour);
			sum.setTheoretical(sum_theoretical_sparse_hour);
			sum.setExperiment(sum_experiment_sparse_hour);
			sum.setUnit("时");
			sum.setMethod("分散");
			sis.add(sum);
			
			sum = new StatisticsInfo();
			sum.setName("小  计[分散，时]");
			sum.setCredits(sum_credicts_sparse_week);
			sum.setPeriod(sum_periods_sparse_week);
			sum.setTheoretical(sum_theoretical_sparse_week);
			sum.setExperiment(sum_experiment_sparse_week);
			sum.setUnit("周");
			sum.setMethod("分散");
			sis.add(sum);
		}
		
		return sis;
	}
	
	public static void printTotal(List<Course> courses){
		if(courses.size() > 5){
			List<Course> subs = new ArrayList<Course>();
			
			subs.add(courses.get(courses.size() - 5));
			subs.add(courses.get(courses.size() - 4));
			subs.add(courses.get(courses.size() - 3));
			subs.add(courses.get(courses.size() - 2));
			subs.add(courses.get(courses.size() - 1));
			
			for (Course course : subs) {
				System.out.println(course.getCredits() + "/" + course.getPeriod());
			}
		}
	}
}
